//
//  File.swift
//  
//
//  Created by Jiang Chencheng on 2024/8/30.
//

enum BizError: UInt {

    // 找不到用户
    case userNotFound = 1001
    // 用户已存在
    case userExisted = 1002
    // 邮箱错误
    case emailInvalid = 1003
    // 手机号错误
    case mobileInvalid = 1004
    // 密码错误
    case passwordInvalid = 1005
    
    // 房间没有找到
    case roomNotFound = 1006
    
    // 存在Partner不能加入该房间
    case roomExistPartner = 1007
    
    // 已加入该房间
    case roomHasJoined = 1008
    
    // 加入其他房间前，请先退出原房间
    case myRoomExistPartner = 1009
    
    // 无法退出房间
    case roomExitInvalid = 1010
    
    // 房间恢复失败
    case roomRestoreInvalid = 1011
    
    // 不能加入自己的房间
    case roomOwner = 1012
    
    case unknown = 2000
    
}

extension BizError: ZeusError {
    
    var reason: String {
        switch self {
        case .userNotFound:
            return "用户不存在"
        case .userExisted:
            return "用户已存在"
        case .emailInvalid:
            return "请输入正确的邮箱"
        case .mobileInvalid:
            return "请输入正确的手机号"
        case .passwordInvalid:
            return "密码错误"
        case .roomNotFound:
            return "房间不存在"
        case .roomExistPartner:
            return "该房间已满员，不能加入该房间"
        
        case .roomHasJoined:
            return "已加入该房间，请勿重复加入"
            
        case .myRoomExistPartner:
            return "请先退出原房间"
            
        case .roomExitInvalid:
            return "无法退出当前房间"
            
        case .roomRestoreInvalid:
            return "恢复原房间失败"
            
        case .roomOwner:
            return "不能加入自己的房间"
        
        default:
            return "未知错误"
        }
    }
    
    var code: UInt {
        self.rawValue
    }
}
